import time

from selenium.webdriver.common.by import By

from cloud_po.pages.base_page import BasePage
from cloud_po.utils.log_utils import logger


class OrderAddPage(BasePage):
    __OCHANNEL = (By.CSS_SELECTOR, '[placeholder="请选择所属渠道"]')
    __OCHANNEL_CHOOSE = (By.XPATH, "//span[text()='学员测试专用']")
    __ADD_BTN = (By.XPATH, "//span[text()='手动添加']")
    __INPUT_1 = (By.XPATH,"(//*[@class='el-input__inner'])[2]")
    __INPUT_2 = (By.XPATH,"(//*[@class='el-input__inner'])[3]")
    __INPUT_3 = (By.XPATH,"(//*[@class='el-input__inner'])[4]")
    __INPUT_4 = (By.XPATH,"(//*[@class='el-input__inner'])[5]")
    __INPUT_5 = (By.XPATH,"(//*[@class='el-input__inner'])[6]")
    __INPUT_6 = (By.XPATH,"(//*[@class='el-input__inner'])[7]")
    # __INPUT_6 = (By.XPATH,"(//*[@class='table-data-cell row-invalid'])[1]")
    __SUBMIT_BTN = (By.XPATH, "//*[text()='全部提交']")
    __SUBMIT_ALERT_BTN = (By.XPATH, "//*[text()='提交']")
    __UPDATE_ALERT_BTN = (By.CSS_SELECTOR, ".el-message-box__btns span")

    def add_order(self,name,phone):
        logger.info("手动创建-录入订单")
        self.do_find(self.__OCHANNEL).click()
        self.do_find(self.__OCHANNEL_CHOOSE).click()
        self.do_find(self.__ADD_BTN).click()

        self.do_find(self.__INPUT_1).click()
        self.do_send_keys(name, self.__INPUT_1)
        self.do_find(self.__INPUT_2).click()
        self.do_send_keys(phone, self.__INPUT_2)
        self.do_find(self.__INPUT_3).click()
        time.sleep(1)
        self.do_find((By.XPATH,"//*[text()='北京市']")).click()
        self.do_find((By.XPATH,"//*[text()='市辖区']")).click()
        self.do_find((By.XPATH,"//*[text()='东城区']")).click()
        self.do_send_keys("东单xxx", self.__INPUT_4)

        self.do_find(self.__INPUT_5).click()
        # //*[@class='list overflow-auto']//div[@class='flex items-center justify-between el-popover__reference']/span
        #  //span[text()='测试商品001（测试仓库）']
        self.do_find((By.XPATH, "//span[text()='测试xs111商品（测试仓库）']")).click()
        self.do_find((By.XPATH, "(//*[contains(text(),'7788')])[1]")).click()

        # 设置渠道价 关闭弹窗
        # self.do_find(self.__SUBMIT_ALERT_BTN).click()
        # time.sleep(1)
        # self.do_find(self.__UPDATE_ALERT_BTN).click()

        self.scroll_to_element(self.__INPUT_6)
        self.do_find_new(self.__INPUT_6).click()
        # self.do_send_keys(1,self.__INPUT_6)
        self.do_find(self.__INPUT_6).send_keys(1)
        time.sleep(2)
        self.do_find(self.__SUBMIT_BTN).click()
        # 弹出提示  # 订单己生成，请在订单列表查看 捕获 返回



